<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 构造函数继承:
    // 原理: 调用父类构造函数,强制将this指向子类在执行过程中创建的实例化对象  => 继承父类实例相关的属性

    // 缺点:
    // 只能继承父类实例的相关属性和方法  不能继承父类原型对象上的相关属性和方法

    function Person(name, age) {
        // this -> 构造函数Person在执行过程中创建的实例化对象
        this.name = name;
        this.age = age;
    }

    Person.prototype.species = "human";
    Person.prototype.skill = function () {
        console.log("thinking");
    }
    Person.prototype.say = function () {
        console.log(this.name, this.age);
    }

    var p = new Person("张三", 18);
    console.log(p);


    function YellowPerson(name, age, hobby) {
        // this -> 构造函数YellowPerson在执行过程中创建的实例化对象
        Person.call(this, name, age); // 调用父类构造函数,强制将this指向子类在执行过程中创建的实例化对象
        this.hobby = hobby;
    }

    YellowPerson.prototype.speak = function () {
        console.log("chinese");
    }

    // debugger;
    var yp = new YellowPerson("张三", 18, "sing");
    console.log(yp);
</script>

</html>